package view.overlay;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.Rectangle2D;

/**
 * PauseButtonOverlay exists as an Overlay that simply adds a "Pause" button
 * to the top right of the screen. May or may not be used in the final game.
 * 
 * @deviation
 * This class didn't exist in the design. It was added for easy access to
 * a pause button.
 * 
 * @author matt
 *
 */
public class PauseButtonOverlay extends PassiveOverlay {
	
	private static final int BUTTON_WIDTH = 180;
	private static final int BUTTON_HEIGHT = 20;
	
	private MouseListener mListener;
	
	private String mText = "Pause";

	@Override
	protected void paint(Graphics g) {
		g.setColor(new Color(100, 100, 100, 255));
		g.fill3DRect(0, 0, BUTTON_WIDTH, BUTTON_HEIGHT, true);
		
		// draw the text
		g.setColor(Color.WHITE);
		Rectangle2D textSize = g.getFontMetrics().getStringBounds(mText, g);
		g.drawString(mText, (int)(BUTTON_WIDTH / 2 - textSize.getWidth() / 2), (int)(BUTTON_HEIGHT / 2 + textSize.getHeight() / 2 ));
	}

	@Override
	public Dimension getPreferredSize() {
		return (new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT));
	}
	
	@Override
	public void onMouseClicked(MouseEvent e) {
		Point p = e.getPoint();
		
		if (p.getX() > 0 && p.getX() < BUTTON_WIDTH) {
			if (p.getY() > 0 && p.getY() < BUTTON_HEIGHT) {
				if (mListener != null) {
					mListener.mouseClicked(e);
				}
			}
		}
	}
	
	public void addMouseListener(MouseListener ml) {
		mListener = ml;
	}
	
	
	
	

}
